import sys

from os import environ
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
# QApplication, QWidget, QDesktopWidget, QHBoxLayout, QVBoxLayout, QPushButton, QLineEdit, QMenuBar, QAction


class MainWindow(QWidget):
    # 初始化窗体, 设置页面布局
    def __init__(self):
        super(MainWindow, self).__init__()

        # 设置标题
        self.setWindowTitle('乔翼 PDF 处理工具 - Qovi PDF Tools')

        # 设置窗口大小
        self.resize(1280, 720)
        self.setMinimumSize(1024, 576)

        # 窗体位置 (居中)
        # qr = self.frameGeometry()
        # cp = QDesktopWidget().availableGeometry().center()
        # qr.moveCenter(cp)

        # 启用显示
        self.show()

        # 创建布局
        layout = QVBoxLayout()

        # 菜单栏
        navi_menu = QMenuBar(self)
        file_sec = navi_menu.addMenu('文件')
        file_sec.addAction(QAction('打开', self))

        # 功能按钮布局
        # PDF合并工具按钮
        btn_pdf_merge = QPushButton('PDF合并工具')
        btn_pdf_merge.setFixedSize(200, 200)
        # 初始化功能按钮布局
        func_layout = QHBoxLayout()
        func_layout.addWidget(btn_pdf_merge)
        func_layout.addStretch()    # 弹性

        # 表单布局
        # form_layout = QHBoxLayout()

        # txt_sign = QLineEdit()
        # txt_sign.setPlaceholderText('请输入商品价格')
        # btn_add = QPushButton('添加')
        # form_layout.addWidget(txt_sign)
        # form_layout.addWidget(btn_add)

        # 页尾布局
        footer_layout = QHBoxLayout()

        # 加载元素排列方式
        layout.addWidget(navi_menu)
        layout.addLayout(func_layout)
        # layout.addLayout(form_layout)
        layout.addLayout(footer_layout)
        layout.addStretch()
        self.setLayout(layout)

    # 试图用方法一键初始化子layout, 但是失败了
    # def init_qh_layout(*q_widget):
    #     qhlayout = QHBoxLayout()
    #     for widget in q_widget:
    #         print(widget)
    #         if(widget.objectName == "__main__"):
    #             pass
    #         print(widget)
    #     #     qhlayout.addWidget(widget)
    #     qhlayout.addStretch()
    #     print('成功init layout')
    #     return qhlayout


# 修复QT窗体初始化警告
def skip_qt_warnings():
    environ["QT_DEVICE_PIXEL_RATIO"] = "0"
    environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
    environ["QT_SCREEN_SCALE_FACTORS"] = "1"
    environ["QT_SCALE_FACTOR"] = "1"


# 主程序入口
if __name__ == '__main__':
    skip_qt_warnings()

    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())
